﻿{template header}
<script type="text/javascript" src="{SITE_URL}js/dialog.js"></script>
<div class="content">
    <div class="dh">注册新用户</div>
    <div class="loginleft">
        <div class="zhuce">
            <div class="zhucet"></div>
            <div class="zhucec">
                <h1><a href="{url user/login}">已有账号？马上登录！</a></h1> 
                <h1>友情贴士：</h1>
                <ul>
                    <li>·我们提醒您注意，您需要注册并登陆，才能享受我们的完整服务进行各项操作。</li>
                    <li>·密码过于简单有被盗的风险，一旦密码被盗你的个人信息有泄漏的危险。</li>
                    <li>·我们拒绝垃圾邮件，请使用有效的邮件地址</li>
                </ul>
            </div>
            <div class="zhuceb"></div>
        </div>
    </div>
    <div class="loginright">
        <div class="lgbdright">
            <ul>
                <li class="a1"></li>
                <li class="a2"></li>
                <li class="a3"></li>
            </ul>
        </div>
        <div class="clr"></div>
        <div class="lgrightc">
            <div class="dl">
                <form name="reg" name="registform"   action="{url user/register}" method="post" onsubmit="return docheck();">
                    <div class="dlc">
                        <!--{if $userinfo}-->
                        <!--{if !$setting['ucenter_open']}-->
                        <div class="shur">
                            <h2><input type="checkbox" name="qqavatar" value="{$userinfo['figureurl_1']}" />使用QQ头像：&nbsp;&nbsp;</h2>
                            <img src="{$userinfo['figureurl_1']}" width="50px" height="50px" />
                        </div>
                        <!--{/if}-->
                        <input type="hidden" name="access_token" value="{$access_token}" />
                        <!--{/if}-->
                        <div class="shur">
                            <h2>&nbsp;&nbsp;用户名：</h2>
                            <input type="text" id="username" name="username" onblur="check_username()" class="input3" value="{$userinfo['nickname']}" />
                            <span id="usernametip" class="input_desc">不超过14个字节(中文，数字，字母和下划线)</span>
                        </div>
                        <div class="clr"></div>
                        <div class="shur">
                            <h2>登录密码：</h2> <input type="password"  name="password" id="password" class="input3" onblur="check_passwd()" />
                            <span id="passwordtip" class="input_desc" onblur="check_passwd()">长度6-14位，字母区分大小写</span>
                        </div>
                        <div class="clr"></div>
                        <div class="shur">
                            <h2>密码确认：</h2> <input type="password"  name="repassword" id="repassword" class="input3" onblur="check_repasswd()"/>
                            <span id="repasswordtip" class="input_desc">与登录密码输入一致</span>
                        </div>
                        <div class="clr"></div>
                        <div class="shur">
                            <h2>电子邮件：</h2> <input type="text"  id="email" name="email" class="input3" onblur="check_email()"/>
                            <span id="emailtip" class="input_desc">请输入正确的电子邮箱地址</span>
                        </div>
                        <!--{if $setting['code_register']}-->
                        <div class="clr"></div>
                        <div class="shur">
                            <h2>&nbsp;&nbsp;验证码：</h2> <input type="text" class="input4" id="code" name="code" onblur="check_code()" />&nbsp;<img align="absmiddle" id="verifycode" onclick="javascript:updatecode();" src="{url user/code}"/><a href="javascript:updatecode();">&nbsp;换一个</a>
                            <span id="codetip" class=""></span>
                        </div>
                        <!--{/if}-->
                        <div class="clr"></div>
                        <div class="shur">
                            <h2>手机号码：</h2> <input type="text"  id="mobile" name="mobile" class="input3" onblur="check_mobile()"/>
                            <span id="mobiletip" class="input_desc">请输入正确的手机号码</span>
                        </div>
                        <div class="clr"></div>
                        <div class="shur">
                            <h2>单位名称：</h2> <input type="text"  id="company" name="company" class="input3"/>                            
                        </div>                        
			            			<div class="clr"></div>
			            			<!--<div class="shur">-->
                            <!--<h2>擅长分类：</h2><input type="text" name="categorys" id="categorys" class="input3" onchange="check_categorys()" onfocus="showselect()" />-->
                             <!--<span id="categorystip" class="input_desc">请选择一个分类</span>-->
                        <!--</div>-->
                        <div class="shur">
                            <h2>擅长分类：</h2><select name="categorys" id="categorys" style="width: 200px" onchange="check_categorys()">{$catetree}</select>
                             <span id="categorystip" class="input_desc">请选择一个分类</span>
                        </div>                        
                        <div class="clr"></div>
                        <div class="shur">
                            <h2>其他擅长：</h2> <input type="text"  id="department" name="department" class="input3"/>                            
                        </div>
                        <div class="clr"></div>
                        <div class="shur3">
                            <input type="submit" name="submit" class="button4"  {if $userinfo}value="提交资料"{else}value="提交注册"{/if}/></div>
                    </div>
                </form>
                <div class="clr"></div>
            </div>
        </div>
        <div class="lgbdright2">
            <ul>
                <li class="a1"></li>
                <li class="a2"></li>
                <li class="a3"></li>
            </ul>
        </div>
    </div>
</div>
<div class="clr"></div>
<script type="text/javascript">
    usernameok=1;
    password=1;
    repasswdok=1;
    emailok=1;
    codeok=1;
    function check_username(){
        var username=$.trim($('#username').val());
        var length=bytes(username);
        if( length <3 || length >15 ){
            $('#usernametip').html("用户名请使用3到15个字符");
            $('#usernametip').attr('class','input_error');
            usernameok=false;
        }else{
            $.post("{SITE_URL}index.php?user/ajaxusername",{username: username}, function(flag){
                if(-1==flag){
                    $('#usernametip').html("此用户名已经存在！");
                    $('#usernametip').attr('class','input_error');
                    usernameok=false;
                }else if(-2==flag){
                    $('#usernametip').html("用户名含有禁用字符！");
                    $('#usernametip').attr('class','input_error');
                    usernameok=false;
                }else{
                    $('#usernametip').html("&nbsp;");
                    $('#usernametip').attr('class','input_ok');
                    usernameok = true;
                }
            });
        }
    }

    function check_passwd(){
        var passwd=$('#password').val();
        if( bytes(passwd) <6|| bytes(passwd)>16){
            $('#passwordtip').html("密码最少6个字符，最长不得超过16个字符");
            $('#passwordtip').attr('class','input_error');
            password =false;
        }else{
            $('#passwordtip').html("&nbsp;");
            $('#passwordtip').attr('class','input_ok');
            password =true;
        }
    }

    function check_categorys(){
        categorysok=1;
        var categorys=$('#categorys').val();
        if(categorys == ""){
            $('#categorystip').html("分类必须选择");
            $('#categorystip').attr('class','input_error');
            categorysok=false;
        }else if (categorys <= 0){
            $('#categorystip').html("分类输入错误");
            $('#categorystip').attr('class','input_error');
            categorysok=false;       
        }else{
            $('#categorystip').html("&nbsp;");
            $('#categorystip').attr('class','input_ok');
            categorysok=true;
        }
    }

    function check_repasswd(){
        repasswdok=1;
        var repassword=$('#repassword').val();
        if( bytes(repassword) <6|| bytes(repassword)>16){
            $('#repasswordtip').html("密码最少6个字符，最长不得超过16个字符");
            $('#repasswordtip').attr('class','input_error');
            repasswdok=false;
        }else{
            if($('#password').val()==$('#repassword').val()){
                $('#repasswordtip').html("&nbsp;");
                $('#repasswordtip').attr('class','input_ok');
                repasswdok=true;
            }else{
                $('#repasswordtip').html("两次密码输入不一致");
                $('#repasswordtip').attr('class','input_error');
                repasswdok=false;
            }
        }
    }

    function check_email(){
        var email=$.trim($('#email').val());
        if (!email.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){
            $('#emailtip').html("邮件格式不正确");
            $('#emailtip').attr('class','input_error');
            emailok=false;
        }else{
            $.post("{SITE_URL}index.php?user/ajaxemail",{email: email}, function(flag){
                if(-1==flag){
                    $('#emailtip').html("此邮件地址已经注册！");
                    $('#emailtip').attr('class','font_orange2');
                    emailok=false;
                }else if(-2==flag){
                    $('#emailtip').html("邮件地址被禁止注册！");
                    $('#emailtip').attr('class','input_error');
                    emailok=false;
                }else{
                    emailok=true;
                    $('#emailtip').html("&nbsp;");
                    $('#emailtip').attr('class','input_ok');
                }
            });
        }
    }

    function check_mobile(){
        var mobile=$.trim($('#mobile').val());
        if (!mobile.match(/^1[3|4|5|8][0-9]\d{4,8}$/)){
            $('#mobiletip').html("手机格式不正确");
            $('#mobiletip').attr('class','input_error');
            mobileok=false;
        }else{            
            $('#mobiletip').html("&nbsp;");
            $('#mobiletip').attr('class','input_ok');
	    mobileok=true;
        }
    }

    function check_code(){
        var code=$.trim($('#code').val());  
        $.post("{SITE_URL}index.php?user/ajaxcode",{code: code}, function(flag){
            if(1==flag){
                $('#codetip').html("&nbsp;");
                $('#codetip').attr('class','input_ok');
                codeok=true;
            }else{
                $('#codetip').html("验证码不匹配！");
                $('#codetip').attr('class','input_error');
                codeok=false;
            }
        });
    }

    function docheck(){
        <!--{if $setting['code_register']}-->
        return (usernameok && repasswdok && emailok && categorysok && codeok && mobileok);
        <!--{else}-->
        return (usernameok && repasswdok && emailok && categorysok && mobileok); 
        <!--{/if}-->
    }

    var sortobj=eval('($category_js)');
    var g_ClassLevel1;
    var g_ClassLevel2;
    var g_ClassLevel3;
    var class_level_1=sortobj.category1;
    var class_level_2=sortobj.category2;
    var class_level_3=sortobj.category3;
    var button_noselect="不选择";

    function getCidValue()
    {
        var _cl1 = document.askform.ClassLevel1;
        var _cl2 = document.askform.ClassLevel2;
        var _cl3 = document.askform.ClassLevel3;
        var _cid = document.askform.cid;
        if(_cl1.value!=0) _cid.value = _cl1.value;
        if(_cl2.value!=0) _cid.value = _cl2.value;
        if(_cl3.value!=0) _cid.value = _cl3.value;
    }
    function FillClassLevel1(ClassLevel1)
    {
        ClassLevel1.options[0] = new Option("aa", "0");
        for(i=0; i<class_level_1.length; i++)
        {
            ClassLevel1.options[i] = new Option(class_level_1[i][1], class_level_1[i][0]);
        }
        // ClassLevel1.options[0].selected = true;
        ClassLevel1.length = i;
    }
    function FillClassLevel2(ClassLevel2, class_level_1_id)
    {
        ClassLevel2.options[0] = new Option(button_noselect, "");
        count = 1;
        for(i=0; i<class_level_2.length; i++){
            if(class_level_2[i][0].toString() == class_level_1_id) {
                ClassLevel2.options[count] = new Option(class_level_2[i][2], class_level_2[i][1]);
                count = count+1;}
        }
        ClassLevel2.options[0].selected = true;
        ClassLevel2.length = count;
    }
    function FillClassLevel3(ClassLevel3, class_level_2_id)
    {
        ClassLevel3.options[0] = new Option(button_noselect, "");
        count = 1;
        for(i=0; i<class_level_3.length; i++) {
            if(class_level_3[i][0].toString() == class_level_2_id) {
                ClassLevel3.options[count] = new Option(class_level_3[i][2], class_level_3[i][1]);
                count = count+1;}
        }
        ClassLevel3.options[0].selected = true;
        ClassLevel3.length = count;
    }
    function ClassLevel2_onchange()
    {
        getCidValue();
        FillClassLevel3(g_ClassLevel3, g_ClassLevel2.value);
        if (g_ClassLevel3.length <= 1) {
            g_ClassLevel3.style.display = "none";
            document.getElementById("jiantou").style.display = "none";
        }
        else {
            g_ClassLevel3.style.display = "";
            document.getElementById("jiantou").style.display = "";
        }
    }
 
    function ClassLevel1_onchange()
    {
        getCidValue();
        FillClassLevel2(g_ClassLevel2, g_ClassLevel1.value);
        ClassLevel2_onchange();
	
    }
    function InitClassLevelList(ClassLevel1, ClassLevel2, ClassLevel3)
    {
        g_ClassLevel1=ClassLevel1;
        g_ClassLevel2=ClassLevel2;
        g_ClassLevel3=ClassLevel3;
        g_ClassLevel1.onchange = Function("ClassLevel1_onchange();");
        g_ClassLevel2.onchange = Function("ClassLevel2_onchange();");
        FillClassLevel1(g_ClassLevel1);
        ClassLevel1_onchange();
    }

    function checkform(form){
        var username = form.username.value;
        var goodatcate = form.goodatcategory.value;
        if(username == '' || goodatcate == '' ){
            alert("用户名或分类不能为空");
            return false;
        }
        return true;
    }

    function showselect(){
        $("#categorys").val("");
        var select = $("#selectcategory").html();
        $.dialog({
            id:'addreason',
            position:'center',
            align:'left',
            width:600,
            height:200,
            title:'选择专家擅长分类',
            fnOk:function(){ 
                var cids='';
                $("input[name='cid']").each(function(){
                    cids +=$(this).val()+' ';
                });
                $("#categorys").val(cids);
                $("#ulid").html($("#selectedcate").html());
                $.dialog.close('addreason');
                var categorys=$('#categorys').val();
                if (categorys == 0) {
                   $("#categorys").val("");
                }
                if(categorys <= 0){
                    $('#categorystip').html("分类必须选择");
                    $('#categorystip').attr('class','input_error');
                }else{
                    $('#categorystip').html("&nbsp;");
                    $('#categorystip').attr('class','input_ok');
                }
            },
            fnCancel:function(){$.dialog.close('addreason')},
            content:'已选中的分类：<br /><ul id="selectedcate"></ul><form name="askform" method="POST" action="index.php?adimin_expert/add">'+'<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
                '<tr valign="top">'+
                '<td width="15%">'+
                '<select  id="ClassLevel1" class="catselect2" size="8" name="classlevel1" style="width:100%" >'+
                '<option selected></option>'+
                '</select>'+
                '</td>'+
                '<td align="center" valign="middle" width="3%">'+
                '<div><b>→</b></div>'+
                '</td>'+
                '<td width="15%">'+
                '<select  id="ClassLevel2"  class="catselect2" size="8" name="classlevel2" style="width:100%">'+
                '<option selected></option>'+
                '</select>'+
                '<td align="center" valign="middle" width="3%">'+
                '<div style="display: none;" id="jiantou"><b>→</b></div>'+
                '</td>'+
                '<td width="15%">'+
                '<select id="ClassLevel3"  class="catselect2" size="8" onchange="getCidValue();"  name="classlevel3" style="width:100%">'+
                '<option selected></option>'+
                '</select>'+
                '</td>'+                
                '</tr>'+
                '<tr valign="top">'+
                '<td class="tiw_biaozhu" colspan="6" align="left" valign="middle">所选分类不能重叠，不能相互包含！</td></tr>'+
                '</table>'+
                '<input type="hidden" value="0" name="cid" />'+
                '<input type="hidden" value="0" name="allcid" />'+
                '</form>'
        });
        InitClassLevelList(document.askform.ClassLevel1, document.askform.ClassLevel2, document.askform.ClassLevel3);
        var selected_id_list="0"
        var blank_pos = selected_id_list.indexOf(" ");
        var find_blank = true;
        if (blank_pos == -1) {
            find_blank = false;
            blank_pos = selected_id_list.length;
        }
        $("#selectedcate").html($("#ulid").html());
    }

    function addcategory(){
        var curcid = $("input[name='cid']").val();
        if(curcid == 0){
            alert("您还未选择分类！");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "index.php?admin_expert/ajaxgetname.html",
            data: "cid="+curcid,
            success: function(categorystr){
                if($("#selectedcate li").size()<=2)
                    $("#selectedcate").append('<li style="color:#3F92F8;"><input type="hidden" name="cids[]"  value="'+curcid+'" />'+categorystr+'&nbsp;&nbsp;<a href="#" onclick="delcategory(this);">删除</a></li>');

            }
        });    
    }
    
</script>
{template footer}